// pages/vistiorApproval/visitorApproval.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentIndex: [5],
    allLogs: [],
    approvalLogs: [],
    showLogs: [],
    items: [{
        name: 0,
        value: '待定',
        checked: 'true'
      },
      {
        name: 2,
        value: '忽略',
      },
      {
        name: -1,
        value: '拒绝'
      },
      {
        name: 1,
        value: '通过'
      },
    ],
    filterGroup: ["0"]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("请求审批数据")
    let _that = this
    wx.request({
      url: 'http://localhost/Wx/AnymousApproveHistory?openid=' + wx.getStorageSync('openid'),
      method: "POST",
      success(res) {
        console.log(res.data)
        _that.setData({
          allLogs: res.data.data
        })
        let tempData = res.data.data
        for (let index in tempData) {
          tempData[index].visible = false
          if (tempData[index].isAgree.toString() in _that.data.filterGroup) {
            console.log("in")
            tempData[index].visible = true
          }
        }
        _that.setData({
          approvalLogs: tempData
        })
        _that.setData({
          showLogs: _that.data.approvalLogs.slice(0, _that.data.currentIndex)
        })
      },
      fail(res) {
        console.log(res)
      }
    })
  },
  checkboxChange: function (e) {
    let _that = this
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
    this.setData({
      filterGroup: e.detail.value
    })
    let tempData = this.data.allLogs
    for (let index in tempData) {
      tempData[index].visible = false
      //in不知道为什么有问题 暴力解决了
      if ((tempData[index].isAgree.toString() == this.data.filterGroup[0]) || (tempData[index].isAgree.toString() == this.data.filterGroup[1]) || (tempData[index].isAgree.toString() == this.data.filterGroup[2]) || (tempData[index].isAgree.toString() == this.data.filterGroup[3])) {
        console.log(tempData[index].isAgree.toString())
        tempData[index].visible = true
      }
    }
    this.setData({
      approvalLogs: tempData
    })
    _that.setData({
      showLogs: _that.data.approvalLogs.slice(0, _that.data.currentIndex)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("reach Bottom")
    let nextIndex = this.data.currentIndex + 5
    let _that = this
    _that.setData({
      currentIndex: nextIndex
    })
    _that.setData({
      showLogs: _that.data.approvalLogs.slice(0, _that.data.currentIndex)
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})